%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lex.h"
#include "parser.h"

extern int yywrap();
%}
DIGIT		[0-9]
NUM			(-{DIGIT})|{DIGIT}|({DIGIT})*
LETTER		[a-zA-Z]
NM			{LETTER}({LETTER}|{DIGIT})*
%%
"function"		{ return FUNCTION; }
"endfunction"	{ return ENDFUNCTION; }
"main:"			{ return MAIN; }
"var"			{ return VAR; }
"add"			{ return ADD; }
"mult"			{ return MULT; }
"label"		 	{ return LABEL; }
"and"			{ return AND; }
"or"			{ return OR; }
"not"			{ return NOT; }
"move"			{ return MOVE; }
"ifzero"		{ return IFZERO; }
"iftrue"		{ return IFTRUE; }
"iffalse"		{ return IFFALSE; }
"ifgreater"		{ return IFGREATER; }
"ifless"		{ return IFLESS; }
"ifequal"		{ return IFEQUAL; }
"goto"			{ return GOTO; }
"call"			{ return CALL; }
"read"			{ return READ; }
"write"			{ return WRITE; }
"return"		{ return RETURN; }
"skip"			{ return SKIP; }
"restore"		{ return RESTORE; }
"setparam"		{ return SETPARAM; }
"param"			{ return PARAM; }
"true"			{ return TRUE; }
"false"			{ return FALSE; }
"ref"			{ return REF; }
"val"			{ return VAL; }
"res"			{ return RES; }
"valres"		{ return VALRES; }
"integer"		{ return INTEGER; }
"string"		{ return STRING; }
"boolean"		{ return BOOLEAN; }
{NUM}			{ trataNumero(); return NUMBER; }
{NM}	  		{ trataTexto(); return NAME; }
[ \t]+			{ ; }
\n				{ lineno++; }
"#".*\n			{ lineno++; }
.				{ return ERROR_TOKEN; }
%%

void trataNumero() {
	yylval.integer = atoi(yytext);
}

void trataTexto() {
	yylval.str = calloc(strlen(yytext), sizeof(char));
	strcpy(yylval.str, yytext);
}
